<meta charset="utf-8">
(#) Potential Plurals

!!! WARNING: Potential Plurals
   This is a warning.

Id
:   `PluralsCandidate`
Summary
:   Potential Plurals
Severity
:   Warning
Category
:   Correctness: Messages
Platform
:   Android
Vendor
:   Android Open Source Project
Feedback
:   https://issuetracker.google.com/issues/new?component=192708
Since
:   1.1.0 (February 2015)
Affects
:   Resource files
Editing
:   This check can *not* run live in the IDE editor
See
:   https://developer.android.com/guide/topics/resources/string-resource.html#Plurals
Implementation
:   [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/StringFormatDetector.kt)
Tests
:   [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/StringFormatDetectorTest.java)

This lint check looks for potential errors in internationalization where
you have translated a message which involves a quantity and it looks
like other parts of the string may need grammatical changes.

For example, rather than something like this:
```xml
  <string name="try_again">Try again in %d seconds.</string>
```
you should be using a plural:
```xml
   <plurals name="try_again">
        <item quantity="one">Try again in %d second</item>
        <item quantity="other">Try again in %d seconds</item>
    </plurals>
```
This will ensure that in other languages the right set of translations
are provided for the different quantity classes.

(This check depends on some heuristics, so it may not accurately
determine whether a string really should be a quantity. You can use
tools:ignore to filter out false positives.

(##) Example

Here is an example of lint warnings produced by this check:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text
res/values/plurals_candidates.xml:4:Warning: Formatting %d followed by
words ("times"): This should probably be a plural rather than a string
[PluralsCandidate]
    &lt;string name="lockscreen_too_many_failed_attempts_dialog_message1"&gt;
    ^
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Here is the source file referenced above:

`res/values/plurals_candidates.xml`:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers
&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2"&gt;
    &lt;!-- Warnings: should be plurals instead --&gt;
    &lt;string name="lockscreen_too_many_failed_attempts_dialog_message1"&gt;
        You have incorrectly drawn your unlock pattern %d times.
        \n\nTry again in &gt;%d seconds.
    &lt;/string&gt;
&lt;/resources&gt;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

You can also visit the
[source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/StringFormatDetectorTest.java)
for the unit tests for this check to see additional scenarios.

(##) Suppressing

You can suppress false positives using one of the following mechanisms:

* Using a special `lint.xml` file in the source tree which turns off
  the check in that folder and any sub folder. A simple file might look
  like this:
  ```xml
  &lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;lint&gt;
      &lt;issue id="PluralsCandidate" severity="ignore" /&gt;
  &lt;/lint&gt;
  ```
  Instead of `ignore` you can also change the severity here, for
  example from `error` to `warning`. You can find additional
  documentation on how to filter issues by path, regular expression and
  so on
  [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html).

* In Gradle projects, using the DSL syntax to configure lint. For
  example, you can use something like
  ```gradle
  lintOptions {
      disable 'PluralsCandidate'
  }
  ```
  In Android projects this should be nested inside an `android { }`
  block.

* For manual invocations of `lint`, using the `--ignore` flag:
  ```
  $ lint --ignore PluralsCandidate ...`
  ```

* Last, but not least, using baselines, as discussed
  [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html).

<!-- Markdeep: --><style class="fallback">body{visibility:hidden;white-space:pre;font-family:monospace}</style><script src="markdeep.min.js" charset="utf-8"></script><script src="https://morgan3d.github.io/markdeep/latest/markdeep.min.js" charset="utf-8"></script><script>window.alreadyProcessedMarkdeep||(document.body.style.visibility="visible")</script>